﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocalGameLibrary
{
    public class LocalGameMetadataProbeManager
    {
        private List<GameProbe> probes = new List<GameProbe>();

        public LocalGameMetadataProbeManager()
        {
            this.probes.Add(new FitGirlRepackProbe());
        }
        public List<GameProbe> Probes { get { return this.probes; } }

        public LocalGameMetadata Probe(String gameFolderFullPath)
        {
            var folderName = Utils.GetLastFolderName(gameFolderFullPath);
            foreach (var probe in this.probes)
            {
                var localGameMetadata = probe.Probe(gameFolderFullPath);

                if (localGameMetadata != null)
                {
                    return localGameMetadata;
                }
            }
            return new LocalGameMetadata // 元数据不存在则使用默认定义
            {
                Org = "Unknown",
                PID = folderName,
                SetupExec = "",
                RecommendedInstallFolderName = "",
                PlayExec = "",
                RepoPath = gameFolderFullPath
            }; ;
        }
    }

    public abstract class GameProbe
    {
        public abstract LocalGameMetadata Probe(String gameFolderFullPath);
    }

    public class FitGirlRepackProbe : GameProbe
    {
        public override LocalGameMetadata Probe(String gameFolderFullPath)
        {
            var folderName = Utils.GetLastFolderName(gameFolderFullPath);
            if (folderName.Contains("[FitGirl Repack]"))
            {
                return new LocalGameMetadata
                {
                    Org = "FitGirl",
                    PID = folderName,
                    SetupExec = "setup.exe",
                    RecommendedInstallFolderName = folderName.Replace("[FitGirl Repack]", "").Trim(),
                    PlayExec = "",
                    RepoPath = gameFolderFullPath
                };
            }
            else
            {
                return null;
            }
        }
    }
}
